/**
 * 
 * nodes: [
 *  {
 *      name: div,
 *      attrs: {
 *          class: 'rich-node',
 *          style: 'width: 100rpx, height: 100rpx'
 *      },
 *      text: '一段文字',
 *      children: []
 *  }
 * ]
 * @param {string} keyword 
 * @param {string} value 
 */
export default function string2nodes(keywords, value) {
    const searchRich = [];
    for (const keyword of keywords) {
        const nodes = [];
        if(keyword.startsWith(value)) {
            const key1 = keyword.slice(0, value.length);
            nodes.push({
                name: 'span',
                attrs: {
                    style: 'color: #f90'
                },
                children: [
                    {
                        type: 'text',
                        text: key1
                    }
                ]
            })
            const key2 = keyword.slice(value.length);
            nodes.push({
                name: 'span',
                attrs: {
                    style: 'color: #000'
                },
                children: [
                    {
                        type: 'text',
                        text: key2
                    }
                ]
            })
        }else {
            nodes.push({
                name: 'span',
                attrs: {
                    style: 'color: #000'
                },
                children: [
                    {
                        type: 'text',
                        text: keyword
                    }
                ]
            });
        } 
        searchRich.push(nodes);
    }
  
    return searchRich;
}